package com.yunao.commons.serachcore.utils;


import com.yunao.commons.utils.Profile;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisUtils {

	private static final JedisPool pool;

	static {
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(8);
		config.setMaxIdle(8);
		config.setMaxWaitMillis(3000);
		config.setTestOnBorrow(false);

		Profile profile = new Profile("search.properties");
		String host = profile.getValue("spring.redis.host", "localhost");
		int port = profile.getIntValue("spring.redis.port", 6379);
		pool = new JedisPool(config, host, port);
	}

	public static Jedis getResource() {
		return pool.getResource();
	}
	
	public static void close() {
		pool.close();
	}

}

